<template>
  <div v-loading="loading && !list[0]" style="min-height: 500px">
    <div
      @click="toDetail(item)"
      v-for="(item, index) in list"
      :key="index"
      class="note-item"
    >
      <div
        :style="{ 'background-image': `url(${item.coverImg})` }"
        class="cover-box"
      ></div>
      <div class="content">
        <div class="title">{{ item.title }}</div>
        <div class="abstract">
          <!-- 一个现代化的node.js开发框架，为高效开发而生,一个现代化的node.js开发框架，为高效开发而生 -->
        </div>
        <div class="info">
          <div class="left">
            <i class="el-icon-collection-tag"></i>
            <!-- 文章所属分类 -->
            <span
              v-for="(v, i) in item.articleClassify"
              :key="i"
              @click.stop="
                $router.push({
                  name: 'classifyDetail',
                  params: { id: v.articleClassifyId },
                })
              "
            >
              {{ v.name }}
            </span>
          </div>
          <div class="right">
            <span v-if="item.browseNum">浏览 {{ item.browseNum }}</span>
            <!-- <span v-if="item.commentNum">评论 {{ item.commentNum }}</span> -->

            <span>{{ formatDate(item.createDate) }}</span>
            <!-- <span><svg-icon icon-class="browse" /> 99</span>
                  <span><svg-icon icon-class="like-fill" /> 20</span> -->
            <!-- <svg-icon icon-class="comment" /> -->
          </div>
        </div>
      </div>
    </div>
    <div v-if="list[0]" class="more">
      <div v-if="!loadEnd" @click="$emit('paging')" class="text">
        加载更多
        <i
          v-if="!loading"
          style="font-weight: 600"
          class="el-icon-arrow-down"
        ></i>
        <i v-else class="el-icon-loading"></i>
      </div>
      <div v-else class="text">博主写的,就这么多了~</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "WorkspaceJsonArticleLists",
  props: {
    loading: {
      default: false,
    },
    loadEnd: {
      default: false,
    },
    lists: {
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      list: [],
    };
  },
  watch: {
    lists: {
      deep: true,
      immediate: true,
      handler() {
        this.list = this.lists;
      },
    },
  },
  mounted() {},
  methods: {
    toDetail(item) {
      this.$router.push(`/note/articleDetail/${item.articleId}`);
    },
    formatDate(d) {
      let date = new Date(d);
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      month = month < 10 ? "0" + month : month;
      let day = date.getDate();
      day = day < 10 ? "0" + day : day;
      return `${year}年${month}月${day}日`;
    },
  },
};
</script>

<style lang="scss" scoped>
.note-item {
  padding: 20px;
  display: flex;
  border-bottom: 1px solid #f5f5f5;
  .cover-box {
    width: 180px;
    min-width: 150px;
    height: 100px;
    margin-right: 10px;
    border-radius: 8px;
    overflow: hidden;
    background: #f5f5f5;
    // background-image: url("https://dongping-blog.oss-cn-hangzhou.aliyuncs.com/systemImage/48380973b3514d2ca84472bf697088d7.png");
    background-position: center center;
    background-size: cover;
    background-repeat: no-repeat;
  }
  .content {
    flex: 1;
    display: flex;
    flex-direction: column;
    .title {
      letter-spacing: 1.2px;
      font-weight: 600;
      transition: all 0.2s;
      padding-top: 5px;
      @include main-text-hidden(2);
      font-size: 17px;
    }
    .abstract {
      flex: 1;
      font-size: 14px;
      color: #999;
      margin: 5px 0 8px;
      @include main-text-hidden(2);
    }
    &:hover {
      color: #2ebc3c !important;
    }
    &:hover .title {
      // text-indent: 10px;
    }
  }
  .info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: #b2b2b2;

    .left {
      i {
        margin-right: 5px;
        font-weight: 600;
      }
      span {
        margin-right: 10px;
        background: #f5f5f5;
        padding: 2px 4px;
        border-radius: 4px;
      }
    }
    .right {
      span {
        margin-left: 10px;
      }
    }
  }
}

.more {
  display: flex;
  justify-content: center;
  padding: 20px 0;
  .text {
    width: 200px;
    height: 30px;
    font-size: 14px;
    line-height: 30px;
    border-radius: 5px;
    text-align: center;
    background: #fff;
    // box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.07);
    color: #666;
  }
}

@media (max-width: 650px) {
  .note-item {
    .cover-box {
      min-width: auto;
      width: 140px;
      height: 80px;
    }
    .title {
      font-size: 16px !important;
    }
    .right {
      span {
        &:nth-child(2) {
          display: none;
        }
      }
    }
  }
}

@media (max-width: 450px) {
  .note-item {
    .cover-box {
      width: 120px;
      height: 80px;
      min-width: auto;
      border-radius: 5px !important;
    }
    .title {
      font-size: 15px !important;
    }
    .left {
      display: none;
    }
    .right {
      font-size: 13px;
      display: flex;
      flex-direction: row-reverse;
      span {
        display: inline !important;
        margin: 0 5px 0 0 !important;
      }
    }
  }
}
</style>
